<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    "user strict";
    const user = {
      data: { name: "小灰", age: 10 },
    //   使用访问器保护数据
    // 外部设置数据
      set age(value) {
        if (typeof value !== "number" || value < 10 || value > 100) {
          throw new Error("年龄格式错误");
        }
        this.data.age=value;
      },
    //   外部获取数据
      get age(){
          return this.data.age;
      }
    };
    user.age=999;
  </script>
</html>
